from rest_framework import serializers

from goods.models import GoodsChannel, SPU, GoodsChannelGroup, GoodsCategory


# 分级列表
class GoodsCategorySerializer(serializers.ModelSerializer):


    class Meta:
        model = GoodsCategory
        fields = ('id','name')

# 频道列表
class GoodsChannelSerializer(serializers.ModelSerializer):

    group = serializers.StringRelatedField(read_only=True)
    group_id = serializers.IntegerField()
    sequence = serializers.IntegerField()
    category = serializers.StringRelatedField()
    category_id = serializers.IntegerField()

    class Meta:
        model = GoodsChannel
        fields = ('id','group','group_id','sequence','category','url','category_id')

# 组列表
class GoodsChannelGroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsChannelGroup
        fields = '__all__'